package api

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"seat-service/initialization"
	"seat-service/response"
	service "seat-service/service/impl"
	"strconv"
)

var buildingService service.BuildingServiceImpl

type BuildingApi struct {
}

func (u *BuildingApi) GetByCampus(c *gin.Context) {
	par := c.Query("id")
	id, _ := strconv.Atoi(par)
	data, err := buildingService.GetByCampusId(id)
	if err != nil {
		initialization.SeatLogger.Error("buildingService.GetByCampusId(id) failed", zap.Error(err))
		resp.Fail(c, response.CodeServerBusy, nil)
	}
	resp.Success(c, response.CodeSuccess, data)
}

func (u *BuildingApi) GetAll(c *gin.Context) {
	data, err := buildingService.GetAll()
	if err != nil {
		initialization.SeatLogger.Error("buildingService.GetAll() failed", zap.Error(err))
		resp.Fail(c, response.CodeServerBusy, nil)
	}
	resp.Success(c, response.CodeSuccess, data)
}

func (u *BuildingApi) Query(c *gin.Context) {
	par := c.Query("param")
	data, err := buildingService.Query(par)
	if err != nil {
		initialization.SeatLogger.Error("buildingService.GetAll() failed", zap.Error(err))
		resp.Fail(c, response.CodeServerBusy, nil)
		return
	}
	resp.Success(c, response.CodeSuccess, data)
}
